//
//  ZCActivityModelContent.m
//
//  Created by   on 16/4/19
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ZCActivityModelContent.h"


NSString *const kZCActivityModelContentCode = @"code";
NSString *const kZCActivityModelContentId = @"id";
NSString *const kZCActivityModelContentRegionCode = @"region_code";
NSString *const kZCActivityModelContentIsvalid = @"isvalid";
NSString *const kZCActivityModelContentCtime = @"ctime";
NSString *const kZCActivityModelContentName = @"name";


@interface ZCActivityModelContent ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ZCActivityModelContent

@synthesize code = _code;
@synthesize contentIdentifier = _contentIdentifier;
@synthesize regionCode = _regionCode;
@synthesize isvalid = _isvalid;
@synthesize ctime = _ctime;
@synthesize name = _name;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.code = [self objectOrNilForKey:kZCActivityModelContentCode fromDictionary:dict];
            self.contentIdentifier = [self objectOrNilForKey:kZCActivityModelContentId fromDictionary:dict];
            self.regionCode = [self objectOrNilForKey:kZCActivityModelContentRegionCode fromDictionary:dict];
            self.isvalid = [self objectOrNilForKey:kZCActivityModelContentIsvalid fromDictionary:dict];
            self.ctime = [self objectOrNilForKey:kZCActivityModelContentCtime fromDictionary:dict];
            self.name = [self objectOrNilForKey:kZCActivityModelContentName fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.code forKey:kZCActivityModelContentCode];
    [mutableDict setValue:self.contentIdentifier forKey:kZCActivityModelContentId];
    [mutableDict setValue:self.regionCode forKey:kZCActivityModelContentRegionCode];
    [mutableDict setValue:self.isvalid forKey:kZCActivityModelContentIsvalid];
    [mutableDict setValue:self.ctime forKey:kZCActivityModelContentCtime];
    [mutableDict setValue:self.name forKey:kZCActivityModelContentName];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.code = [aDecoder decodeObjectForKey:kZCActivityModelContentCode];
    self.contentIdentifier = [aDecoder decodeObjectForKey:kZCActivityModelContentId];
    self.regionCode = [aDecoder decodeObjectForKey:kZCActivityModelContentRegionCode];
    self.isvalid = [aDecoder decodeObjectForKey:kZCActivityModelContentIsvalid];
    self.ctime = [aDecoder decodeObjectForKey:kZCActivityModelContentCtime];
    self.name = [aDecoder decodeObjectForKey:kZCActivityModelContentName];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_code forKey:kZCActivityModelContentCode];
    [aCoder encodeObject:_contentIdentifier forKey:kZCActivityModelContentId];
    [aCoder encodeObject:_regionCode forKey:kZCActivityModelContentRegionCode];
    [aCoder encodeObject:_isvalid forKey:kZCActivityModelContentIsvalid];
    [aCoder encodeObject:_ctime forKey:kZCActivityModelContentCtime];
    [aCoder encodeObject:_name forKey:kZCActivityModelContentName];
}

- (id)copyWithZone:(NSZone *)zone
{
    ZCActivityModelContent *copy = [[ZCActivityModelContent alloc] init];
    
    if (copy) {

        copy.code = [self.code copyWithZone:zone];
        copy.contentIdentifier = [self.contentIdentifier copyWithZone:zone];
        copy.regionCode = [self.regionCode copyWithZone:zone];
        copy.isvalid = [self.isvalid copyWithZone:zone];
        copy.ctime = [self.ctime copyWithZone:zone];
        copy.name = [self.name copyWithZone:zone];
    }
    
    return copy;
}


@end
